/* GUI CONVERTED from reoptr14.p (converter v1.76) Sun Aug 25 20:59:49 2002 */
/* reoptr14.p - LABOR SCRAP TRANSACTION BY PART (REPETITIVE)            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.3.4 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 5.0      LAST MODIFIED: 05/19/89   BY: emb                 */
/* REVISION: 5.0      LAST MODIFIED: 10/17/90   BY: emb  *B801          */
/* REVISION: 6.0      LAST MODIFIED: 09/25/90   BY: SMM  *D072          */
/* REVISION: 6.0      LAST MODIFIED: 10/17/90   BY: SMM  *D104          */
/* REVISION: 6.0      LAST MODIFIED: 11/20/90   BY: emb  *D223          */
/* REVISION: 6.0      LAST MODIFIED: 03/22/91   BY: emb  *D448          */
/* REVISION: 6.0      LAST MODIFIED: 08/12/91   BY: pma  *D806          */
/* REVISION: 7.0      LAST MODIFIED: 10/08/91   BY: pma *F003*          */
/* REVISION: 7.0      LAST MODIFIED: 03/09/92   BY: smm *F230*          */
/* REVISION: 7.0      LAST MODIFIED: 03/23/92   BY: pma *F089*          */
/* REVISION: 7.0      LAST MODIFIED: 03/30/92   BY: emb *F331*          */
/* REVISION: 7.0      LAST MODIFIED: 06/17/92   BY: emb *F662*          */
/* REVISION: 7.0      LAST MODIFIED: 06/26/92   BY: emb *F705*          */
/* REVISION: 7.3      LAST MODIFIED: 10/13/92   BY: emb *G184*          */
/* REVISION: 7.3      LAST MODIFIED: 02/24/93   BY: emb *G760*          */
/* REVISION: 7.4      LAST MODIFIED: 07/22/93   BY: pcd *H039*          */
/* REVISION: 7.4      LAST MODIFIED: 02/24/94   BY: pma *GI84*          */
/* REVISION: 7.5      LAST MODIFIED: 10/24/94   by: mwd *J034*          */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN76*          */
/* REVISION: 7.4      LAST MODIFIED: 12/29/94   BY: cpp *FT95*          */
/* REVISION: 7.3      LAST MODIFIED: 02/07/95   BY: qzl *F0H9*          */
/* REVISION: 7.3      LAST MODIFIED: 05/11/95   BY: ais *G0MM*          */
/* REVISION: 8.5      LAST MODIFIED: 05/01/96   BY: jym *G1MN*          */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: bjl *K001*          */
/* REVISION: 8.5      LAST MODIFIED: 09/09/96   BY: *J14S* Julie Milligan    */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.9.3.3    BY: Jean Miller          DATE: 04/26/02  ECO: *P06H*  */
/* $Revision: 1.9.3.4 $         BY: Vivek Gogte          DATE: 08/06/02  ECO: *N1QQ*  */
/************************************************************************/
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */
{mfdtitle.i "2+ "}
{gldydef.i new}
{gldynrm.i new}

define new global shared variable global_rsntyp as character.

define new shared variable conv         like um_conv label "Conv".
define new shared variable wr_recno     as recid.
define new shared variable wc_recno     as recid.
define new shared variable op_recno     as recid.
define new shared variable comp         like ps_comp.
define new shared variable eff_date     as date.
define new shared variable wo_recid     as recid.
define new shared variable wo_recno     as recid.
define new shared variable ophist_recid as recid.
define new shared variable pay_rate     like emp_pay_rate.
define new shared variable qty          like op_qty_comp
                                        label "Qty Scrapped".
define new shared variable site         like rps_site no-undo.
define new shared variable prline       like rps_line no-undo.
define new shared variable part         like op_part no-undo.
define new shared variable op           like ps_op no-undo.
define new shared variable bom_code     as character format "x(18)"
                                        label "BOM".
define new shared variable routing      as character format "x(18)"
                                        label "Routing".
define new shared variable mod_issrc    like mfc_logical
                                        label "Modify Backflush".
define new shared variable schedule_id  like wo_lot.
define new shared variable undo-all     like mfc_logical no-undo.

define variable yn            like mfc_logical.
define variable start_run     as character format "99:99:XX"
                              label "Start Time".
define variable stop_run      like start_run
                              label "Elapsed or Stop Time".
define variable last_date     like op_date.
define variable rsn_desc1     like rsn_desc.
define variable locked-file   as character.
define variable msg-counter   as integer no-undo.
define variable um            like pt_um.
define variable tot_units     like op_qty_comp.
define variable disp_units    as character format "x(15)".
define variable getop-vars-ok as logical.   /*DO NOT MAKE no-undo*/
define variable undo_all      like mfc_logical no-undo.

define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.

define new shared frame a.
define new shared frame a1.
define buffer ophist for op_hist.

define new shared temp-table scrap_output_wip_lot
   field sowl_lotser       like wlt_lotser
   field sowl_ref          like wlt_ref
   field sowl_reason_code  like rsn_code
   field sowl_qty          like wlt_qty
   index sowl_ix is unique primary
      sowl_lotser
      sowl_ref
      sowl_reason_code.

/* DEFINE VARIABLES FOR BILL OF MATERIAL EXPLOSION */
{gpxpld01.i "new shared"}

{gpglefv.i}

/* Input frame definition */
{reopf14a.i}

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.

if available mfc_ctrl and mfc_logical = true then do:
   {pxmsg.i &MSGNUM=5122 &ERRORLEVEL=3}
   message.
   message.
   undo, leave.
end.

assign
   last_date = today
   site = global_site.

find si_mstr no-lock where si_site = site no-error.
display
   site si_desc when (available si_mstr)
   last_date
with frame a1.

/* DISPLAY */
view frame a1.
view frame a.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   do with frame a1:
      ststatus = stline[1].
      status input ststatus.

      prompt-for
         site
         last_date
      with frame a1
      editing:
         if frame-field = "site" then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp.i si_mstr site si_site site si_site si_site}
            if recno <> ? then do:
               display
                  si_site @ site
                  si_desc.
            end.
         end.
         else do:
            readkey.
            apply lastkey.
         end.
      end.

      assign
         site
         last_date
         eff_date = last_date.

      find si_mstr
      no-lock
         where si_site = site no-error.
      if not available si_mstr then do:
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3} /* SITE DOES NOT EXIST */
         next-prompt site.
         undo, retry.
      end.

      {gprun.i ""gpsiver.p""
         "(input site, input recid(si_mstr), output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0 then do:
         /*USER DOES NOT HAVE ACCESS TO THIS SITE */
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         next-prompt site.
         undo, retry.
      end.

      display si_desc with frame a1.
      global_site = si_site.

      /* Check effective date */

      {gpglef1.i
         &module = ""WO""
         &entity = si_entity
         &date = last_date
         &prompt = "last_date"
         &frame = "a1"
         &loop = "mainloop"
         }

      ststatus = stline[1].
      status input ststatus.

      detail-loop:
      repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

         prompt-for
            op_part
            op_wo_op
            prline
         with frame a
         editing:
            if frame-field = "op_part" then do:

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp.i pt_mstr op_part pt_part op_part pt_part pt_part}

               if recno <> ? then do:
                  find ptp_det no-lock where ptp_part = pt_part
                     and ptp_site = input site no-error.

                  if available ptp_det then do:
                     if ptp_routing > ""
                     then
                        routing = ptp_routing.
                     else
                        routing = "".
                     if ptp_bom_code > ""
                     then
                        bom_code = ptp_bom_code.
                     else
                        bom_code = "".
                  end.
                  else do:
                     if pt_routing > ""
                     then
                        routing = pt_routing.
                     else
                        routing = "".
                     if pt_bom_code > ""
                     then
                        bom_code = pt_bom_code.
                     else
                        bom_code = "".
                  end.

                  display pt_part @ op_part pt_desc1.

                  find first ro_det no-lock
                     where ro_routing = if routing > ""
                                        then routing
                                        else pt_part no-error.
                  if available ro_det
                  then
                     display
                        ro_op @ op_wo_op
                        ro_desc.
                  else
                     display
                        "" @ op_wo_op
                        "" @ ro_desc.

                  display "" @ prline "" @ ln_desc.
                  for each lnd_det no-lock where
                        lnd_site = site and lnd_part = pt_part
                        and (lnd_start <= input last_date or lnd_start = ?)
                     with frame a:
                     find ln_mstr no-lock where ln_line = lnd_line
                        and ln_site = lnd_site no-error.
                     if available ln_mstr
                     then
                        display
                           ln_line @ prline
                           ln_desc.
                     else
                        display
                           "" @ prline
                           "" @ ln_desc.
                     leave.
                  end.
                  display routing bom_code with frame a.
               end.
               recno = ?.
            end.
            else
            if frame-field = "op_wo_op"
               and can-find (pt_mstr where pt_part = input op_part)
            then do:

               find pt_mstr no-lock where
                  pt_part = input op_part no-error.
               find ptp_det no-lock where ptp_part = pt_part
                  and ptp_site = input site no-error.

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp01.i ro_det op_wo_op ro_op
                  "if available ptp_det then if ptp_routing > """"
                    then ptp_routing else ptp_part
                    else if pt_routing > """" then pt_routing else pt_part"
                  ro_routing ro_routing}

               if recno <> ? then do:
                  display ro_op @ op_wo_op ro_desc.
               end.
               recno = ?.
            end.
            else if frame-field = "prline" then do:

               {mfnp05.i lnd_det lnd_line
                  "lnd_site = input site and lnd_part = input op_part"
                  lnd_line "input prline"}
               if recno <> ? then do:
                  find ln_mstr no-lock where ln_line = lnd_line
                     and ln_site = lnd_site no-error.
                  display lnd_line @ prline.
                  if available ln_mstr then display ln_desc.
               end.
            end.
            else do:
               readkey.
               apply lastkey.
            end.
         end.

         assign prline.

         find pt_mstr no-lock where pt_part = input op_part no-error.
         if not available pt_mstr then do:
            {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
            next-prompt op_part.
            undo, retry.
         end.

         find first ln_mstr no-lock where ln_site = site no-error.
         if available ln_mstr or prline <> "" then do:

            find ln_mstr no-lock where ln_line = prline
               and ln_site = site no-error.
            if not available ln_mstr then do:
               {pxmsg.i &MSGNUM=8526 &ERRORLEVEL=3}
               next-prompt prline.
               display "" @ ln_desc.
               undo,retry.
            end.
            display ln_desc.
         end.
         else
            display "" @ ln_desc.

         /* Added section to locate proper schedule to update */
         assign
            part = input op_part
            op   = input op_wo_op.

         {gprun.i ""reoptr1b.p""
            "(site, prline, part, op, last_date,
              output routing, output bom_code, output schedule_id)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if keyfunction(lastkey) = "end-error" then undo, retry.

         if schedule_id = ?
         then do:
            /* Unexploded schedule with consumption period */
            {pxmsg.i &MSGNUM=325 &ERRORLEVEL=3}
            next-prompt op_part.
            undo, retry.
         end.

         /* Locate proper routing and bom code */
         {gprun.i ""reop14a.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if keyfunction(lastkey) = "end-error" then undo, retry.
         if undo-all then undo, retry.

         find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
         find wr_route no-lock where recid(wr_route) = wr_recno.

         if not wr_milestone then do:
            {pxmsg.i &MSGNUM=560 &ERRORLEVEL=3} /* NOT A MILESTONE */
            undo, retry.
         end.

         if available ro_det then display ro_desc.
         else display wr_desc @ ro_desc.
         find pt_mstr where pt_part = wr_part no-lock no-error.
         if available pt_mstr then display pt_desc1.
         else display " " @ pt_desc1.

         status input.

         do transaction
         with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


            create op_hist.

            {mfnoptr.i}

            assign
               op_wo_nbr    = wr_nbr
               op_wo_op     = wr_op
               op_wo_lot    = wr_lot
               op_type      = "SCRAP"
               op_tran_date = today
               op_wkctr     = wr_wkctr
               op_mch       = wr_mch
               op_date      = last_date
               op_site      = site
               op_line      = prline
               op_milestone = wr_milestone
               op_part      = wr_part
               qty          = wr_qty_rjct
               ophist_recid = recid(op_hist)
               op_recno     = recid(op_hist)
               start_run    = "000000"
               stop_run     = "000000"
               um           = pt_um
               conv         = 1.

            display
               op_wkctr
               op_mch
               wr_qty_rjct
               qty
               um
               conv
               " " @ disp_units
               op_trnbr format ">>>>>>>9".

            if is_wiplottrace_enabled() then
               run init_bkfl_reject_wip_lot_temptable
                  in h_wiplottrace_procs.

            find wc_mstr where wc_wkctr = op_wkctr
               and wc_mch = op_mch no-lock no-error.
            if available wc_mstr then do:
               display wc_desc.
               find dpt_mstr no-lock where dpt_dept = wc_dept no-error.
               if available dpt_mstr then do:
                  op_dept = wc_dept.
                  display op_dept dpt_desc.
               end.
               else display " " @ dpt_desc.
            end.
            else display " " @ wc_desc " " @ op_dept " " @ dpt_desc.

            global_rsntyp = "scrap".

            set_ophist:
            do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


               /* CALL INTERNAL PROCEDURE p-getop-vars. CREATED   */
               /* TO REDUCE ACTION SEGMENT SIZE                   */
               run p-getop-vars.

               if not getop-vars-ok then
                  undo detail-loop, retry detail-loop.

               if is_wiplottrace_enabled()
                  and is_operation_queue_lot_controlled
                  (op_wo_lot, op_wo_op, OUTPUT_QUEUE)
               then do:
                  run get_std_scrap_reject_wip_lots_from_user
                     (input wr_lot,
                     input wr_op,
                     input qty,
                     input conv,
                     input um,
                     input wo_site,
                     input op_wkctr,
                     input op_mch,
                     output undo_all).

                  if undo_all then undo detail-loop, retry detail-loop.
               end.

               yn = yes.
               {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=yn}
               if yn = no then undo, retry.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.


            msg-counter = 0.
            repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

               release wo_mstr.
               release wr_route.
               find wo_mstr exclusive-lock
                  where recid(wo_mstr) = wo_recno
                  no-wait no-error.
               if available wo_mstr then do:
                  find wr_route exclusive-lock
                     where recid(wr_route) = wr_recno
                     no-wait no-error.
               end.
               if locked wo_mstr
                  or locked wr_route
               then do:
                  if locked wo_mstr then locked-file = "wo_mstr".
                  else
                  if locked wr_route then locked-file = "wr_route".
                  if msg-counter modulo 100 = 0 then do:
                     {pxmsg.i &MSGNUM=1400 &ERRORLEVEL=1
                              &MSGARG1=locked-file
                              &MSGARG2=kblabel(""end-error"")
                              &MSGARG3="fill(""."",(msg-counter / 100) mod 20)"}
                     readkey pause 1.
                     if keyfunction(lastkey) = "end-error" then leave.
                     apply lastkey.
                  end.
                  msg-counter = msg-counter + 1.
                  next.
               end.
               if available wo_mstr and available wr_route then leave.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.

            hide message.

            if keyfunction(lastkey) = "end-error" then undo, leave.

            if is_wiplottrace_enabled() and
               is_operation_queue_lot_controlled(op_wo_lot, op_wo_op, OUTPUT_QUEUE)
            then do:
               if qty <> 0 then
                  run std_scrap_wip_lots (input recid(op_hist), input conv).
            end.
            else do:
               assign
                  qty         = qty * conv
                  op_qty_rjct = - qty
                  op_qty_comp = qty
                  wr_qty_rjct = wr_qty_rjct + op_qty_rjct
                  wr_qty_wip  = wr_qty_wip - qty.
               {gprun.i ""reoptre.p""}
/*GUI*/ if global-beam-me-up then undo, leave.
 /* Post value to G/L */
               {gprun.i ""reoptre1.p""}
/*GUI*/ if global-beam-me-up then undo, leave.
 /* Update Schedule */
            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
end.
/*GUI*/ if global-beam-me-up then undo, leave.

status input.

if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.

/* * * * * * * * * * * * INTERNAL PROCEDURES SECTION * * * * * * * * * * * * */

PROCEDURE p-getop-vars:

   /*RE-READ REQUIRED RECORD BUFFERS FOR THIS PROCEDURE */

   find op_hist where recid(op_hist) = op_recno.
   find pt_mstr no-lock where pt_part = op_part no-error.
   getop-vars-ok = no.

   do with frame a on error undo:
/*GUI*/ if global-beam-me-up then undo, leave.


      getop-vars-ok = yes.

      set
         op_wkctr
         op_mch
         op_dept
         op_emp
         op_shift
         qty
         um
         conv
         op_rsn
      editing:

         if frame-field = "op_wkctr"
            or frame-field = "op_mch"
         then do:
            {mfnp.i wc_mstr op_wkctr wc_wkctr
               op_wkctr wc_wkctr wc_wkctr}
            if recno <> ? then do:
               display
                  wc_wkctr @ op_wkctr
                  wc_mch   @ op_mch wc_desc.

               find dpt_mstr no-lock where
                  dpt_dept = wc_dept no-error.
               if available dpt_mstr then do:
                  op_dept = dpt_dept.
                  display op_dept dpt_desc.
               end.
               else display " " @ dpt_desc.
            end.
         end.
         else if frame-field = "op_dept" then do:
            {mfnp.i dpt_mstr op_dept dpt_dept
               op_dept op_dept dpt_dept}
            if recno <> ? then
               display dpt_dept @ op_dept dpt_desc.
         end.
         else if frame-field = "op_emp" then do:
            {mfnp.i emp_mstr op_emp emp_addr
               op_emp emp_addr emp_addr}
            if recno <> ? then
               display
                  emp_addr @ op_emp
                  emp_fname + " " + emp_lname @ ad_name.
         end.
         else if frame-field = "op_rsn" then do:
            {mfnp01.i rsn_ref op_rsn rsn_code
               ""scrap"" rsn_type rsn_type}
            if recno <> ? then
               display
                  rsn_code @ op_rsn
                  rsn_desc @ rsn_desc1.
         end.
         else do:
            ststatus = stline[3].
            status input ststatus.
            readkey.
            apply lastkey.
         end.
      end. /* editing set op_wkctr op_mch op_dept ...*/

      find wc_mstr where wc_wkctr = op_wkctr
         and wc_mch = op_mch no-lock no-error.
      if not available wc_mstr then do:
         {pxmsg.i &MSGNUM=519 &ERRORLEVEL=3} /* Work center does not exist */
         undo, retry.
      end.
      display wc_desc.
      wc_recno = recid(wc_mstr).

      find dpt_mstr where dpt_dept = op_dept no-lock no-error.
      if not available dpt_mstr then do:
         next-prompt op_dept.
         {pxmsg.i &MSGNUM=532 &ERRORLEVEL=3} /* Department does not exist */
         undo, retry.
      end.
      display dpt_desc.

      if op_emp > "" then do:
         find emp_mstr where emp_addr = op_emp no-lock no-error.
         if not available emp_mstr then do:
            /* Employee number does not exist */
            {pxmsg.i &MSGNUM=520 &ERRORLEVEL=2}
            display " " @ ad_name.
         end.
         else display emp_fname + " " + emp_lname @ ad_name.

         if available emp_mstr
            and lookup(emp_status,"AC,PT") = 0 then do:
            next-prompt op_emp.
            /* Employee not on active status */
            {pxmsg.i &MSGNUM=4027 &ERRORLEVEL=3}
            undo,retry.
         end.
      end.
      else display " " @ ad_name.

      if um <> pt_um or conv <> 1 then do:
         if not conv entered then do:
            {gprun.i ""gpumcnv.p""
               "(input um, input pt_um, input op_part, output conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            if conv = ? then do:
               {pxmsg.i &MSGNUM=33 &ERRORLEVEL=2}
               conv = 1.
            end.
            display conv.
         end.
         assign
            tot_units  = qty * conv
            disp_units = string(tot_units,"->,>>>,>>9.9<<<<<<<<")
                       + " " + pt_um
            disp_units = fill(" ",max(15 - length(disp_units),0))
                       + disp_units.
         display disp_units.
      end.
      else display conv " " @ disp_units.

      find rsn_ref where rsn_code = op_rsn
         and rsn_type = "scrap" no-lock no-error.
      if available rsn_ref then
         display rsn_desc @ rsn_desc1.
      else do:
         display " " @ rsn_desc1.
         if op_rsn > "" then do:
            {pxmsg.i &MSGNUM=534 &ERRORLEVEL=2}
         end.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* do with frame a */

END PROCEDURE. /* p-getop-vars */

PROCEDURE std_scrap_wip_lots:
   define input parameter ip_ophist_recid as recid no-undo.
   define input parameter ip_umconv_factor as decimal no-undo.

   define variable ophist_recid   as recid no-undo.
   define variable trans_type     like op_type no-undo.
   define variable nbr            like op_wo_nbr no-undo.
   define variable id             like wl_prodby_id no-undo.
   define variable op             like wl_prodby_op no-undo.
   define variable emp            like op_emp no-undo.
   define variable wkctr          like op_wkctr no-undo.
   define variable mch            like op_mch no-undo.
   define variable dept           like op_dept no-undo.
   define variable shift          like op_shift no-undo.
   define variable effdate        like op_date no-undo.
   define variable site           like si_site no-undo.
   define variable first_record   as logical initial true.
   define variable conv_qty_scrap as decimal no-undo.

   for first op_hist where recid(op_hist) = ip_ophist_recid
   exclusive-lock:
   end.

   assign
      trans_type = op_type
      nbr        = op_wo_nbr
      id         = op_wo_lot
      op         = op_wo_op
      emp        = op_emp
      wkctr      = op_wkctr
      mch        = op_mch
      dept       = op_dept
      shift      = op_shift
      effdate    = op_date
      site       = op_site
      .

   ophist_recid = ip_ophist_recid.

   for each scrap_output_wip_lot no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.

      /*CREATE OP_HIST IF WE NEED TO*/

      if not first_record then do:
         {gprun.i ""reophist.p""
            "(input trans_type,
              input id,
              input op,
              input emp,
              input wkctr,
              input mch,
              input dept,
              input shift,
              input effdate,
              output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      first_record = false.

      /*UPDATE OP_HIST*/

      for first op_hist where recid(op_hist) = ophist_recid
      exclusive-lock:
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      conv_qty_scrap = sowl_qty * ip_umconv_factor.

      assign
         op_wip_lotser = sowl_lotser
         op_wip_ref    = sowl_ref
         op_qty_rjct   = - conv_qty_scrap
         op_qty_comp   = conv_qty_scrap
         op_wo_nbr     = nbr
         .

      /*UPDATE WR_ROUTE*/
      for first wr_route
         where wr_lot = op_wo_lot and wr_op = op_wo_op
      exclusive-lock:
      end.

      assign
         wr_qty_rjct = wr_qty_rjct - conv_qty_scrap
         wr_qty_wip = wr_qty_wip - conv_qty_scrap
         .

      /*POST VALUE TO GL AND UPDATE SCHEDULE*/

      for first wc_mstr
         where wc_wkctr = op_wkctr and wc_mch = op_mch
      no-lock:
      end.

      assign
         wr_recno = recid(wr_route)
         wc_recno = recid(wc_mstr)
         op_recno = recid(op_hist)
         .

      {gprun.i ""reoptre.p""}
/*GUI*/ if global-beam-me-up then undo, leave.
  /* Post value to G/L */
      {gprun.i ""reoptre1.p""}
/*GUI*/ if global-beam-me-up then undo, leave.
 /* Update Schedule */

      /*REDUCE THE QUEUE WIP QOH AT THIS OPERATION*/
      run change_wip_qty_alloc_qoh in h_wiplottrace_procs
        (input op_wo_lot,
         input op_wo_op,
         input sowl_lotser,
         input sowl_ref,
         input op_site,
         input op_wkctr,
         input op_mch,
         input REJECT_QUEUE,
         input op_wo_lot,
         input op_wo_op,
         input - conv_qty_scrap).

      /*UPDATE THE WIP LOT MASTER*/
      run update_wip_lot_master_record in h_wiplottrace_procs
        (input op_wo_lot,
         input op_wo_op,
         input sowl_lotser,
         input CUM_SCRAPPED,
         input conv_qty_scrap).
   end. /* if available reject_wip_lots */
END PROCEDURE.

PROCEDURE get_std_scrap_reject_wip_lots_from_user:
   define input parameter ip_wo_id         like wl_prodby_id no-undo.
   define input parameter ip_wo_op         like wl_prodby_op  no-undo.
   define input parameter ip_qty_proc      as decimal no-undo.
   define input parameter ip_umconv_factor as decimal no-undo.
   define input parameter ip_um            as character no-undo.
   define input parameter ip_site          like si_site no-undo.
   define input parameter ip_wkctr         like wc_wkctr no-undo.
   define input parameter ip_mch           like wc_mch no-undo.
   define output parameter op_undo_all     like mfc_logical no-undo.

   {gprunmo.i
      &program = ""wluissr.p""
      &module = "AWT"
      &param = """(input ip_wo_id,
        input ip_wo_op,
        input ip_qty_proc,
        input ip_umconv_factor,
        input ip_um,
        input ip_site,
        input ip_wkctr,
        input ip_mch,
        output op_undo_all)"""}
END PROCEDURE.
